The Clean Code Talks - "Global State and Singletons" Video
Google Tech Talks November 13, 2008
ABSTRACT
The Clean Code Talk Series
Speaker: Misko Hevery
Comments on "The Clean Code Talks - "Global State and Singletons""
Damn, good I never ... Damn, good I never saw such? Singleton abusing.
thegoodteacher(dot) ... thegoodteacher(dot)com?
Did this ass? ... Did this ass? really just call a computer a finite-state machine? Is he high?
Whatever method ... Whatever method needs this 'current time of day' should have the time? of day passed into it; so that you can run your test with a known time of day. Simply having deep areas of your code pulling various outside values without explicit control is asking for testing trouble.
What are you going ... What are you going to test it against??
But what if? I have ... But what if? I have a method that, say, gets the current time of day? Even given the exact same input, it will, of course, return different values depending on external conditions. What's wrong with that? It seems perfectly intuitive and testable to me!
There is a ton of ... There is a ton of great design information in this talk.?
@blenderpanzi @ ... @blenderpanzi @magwo
I think you guys are saying the same thing. :p
If x == y? && f(x) != f(y), f is dependent on global state. If f modifies state, it has a side effect.
Well from a ... Well from a theoretical point of view there are basically two concepts: functional and logic orientated. So I guess all existing languages have to be described with one of these? two (lambda calculus is used as the theoretical background for most programming languages), which explains why my professor said in a theoretical lecture that global state (or even mutable objects) are basically side effects. :)
This is true in a ... This is true in a purely functional language. In object-oriented languages with mutable objects, side effects do not really imply global state. Objects are created in local scopes, and if two objects are created equally, you should get the same result from obj1.f(x) as obj2.f(x), as well as obj1.f(y) and obj2.f(y)? if x==y. Unless you have global state, like static variables, random generators (that are commonly based on the global variable known as the clock) and so on.
AFAIK: if x == y && ... AFAIK: if x == y && f(x) != f(y) then there is a side effect. Having global state (or just object oriented programming with mutable objects)? you get such a situation, because there is a hidden parameter. But maybe I did understand something wrong.
That is not correct ... That is not correct. They are obviously not the same thing IMO. However? having a mutable global state makes any code anywhere _potentially_ side effect laden, to an unknown extent, because the state changes can propagate between singletons etc.
If you do not have global state, the side effects can only happen in the set of objects that you are currently testing in isolation, so they can be expected and checked for correctness.
Well, one of my ... Well, one of my professor said global state equals side effects, mathematically spoken.? I just believed him.
better use charge(- ... better use charge(-100) ;-)?
Actually it's not ... Actually it's not at all about side effects. Side effects do? not present a big problem to testability of code, but global state (global side effects) does.
At 24:10
again: He ... At 24:10
again: He wants a functional and sideeffect free language. In? haskell you CAN change the order of expressions! Why isn't he saying that he does not like OOP languages but would like to use a functional language?
I'm at 8:30 and ... I'm at 8:30 and wonder if he will name the child by its? name in this talk and say: SIDEEFFECTS! He wants a sideeffect free language. He should use haskell.
God I? learned this ... God I? learned this the hard way at my internship. It DOES drive you crazy...
i learned - next ... i learned - next time I test a credit card system? - I will use charge(1) :)
SECRETLY!? SECRETLY!?
static data is ok ... static data is ok if it an implementation detail and it doesn't change? the interface
I used the same ... I used the same term that wikipedia uses, IoC, which also states that "Dependency Injection" (same thing, different name? (of dependency inversion)) is a part of IoC.
Could you please elaborate? From where does an object get its references if not? through the constructor/setters or the global environment in a language like Java?
Of course, I don't take regular method arguments into consideration now, but that's also a place to where dependencies can be moved.
Side-effects are ... Side-effects are probably the heart of the matter, and pure functional programming does remedy that.
But still, what I think the point was is "Inversion of Control"; that objects' relations should? be well thought out and explicit. That is, it's very bad to use global state as a means to let objects find its environment (and unlike scheme etc., java has got only the object's state and the global environment).
Also, there's long been a notion of "mutators"/"inspectors"/etc. kinds of methods.
Don't you think ... Don't you think that Aspect- Oriented programming is the best solution for complex initialization? mechanism with both init and finalization methods to be called.
Seriously SFTU and ... Seriously SFTU and stop? interrupting.
The part about the ... The part about the deceptive API is a good summary of why not to have global (mutable) state in any form. Singleton-ness is a big design decision to make, and should never be enforced by a class. It's better to let the user of the class make that decision.
It may be tempting to let objects discover their environment? through the ether that is the global name space. But objects should only know what you let them know.
Interesting thought to make a separation of "Value" and "Service" objects.
Domains International This domain is owned by DomainsInternational.Net located online at www.domainsinternational.net where you can find dozens of domains for sale on the same category (adults, dictionary words, 1-word domains).
Domains International (Blog) Blog managed by DomainsInternational.Net with articles, links, photos, domains auctions and other information.
Asian Women For Marriage at Asian Dating Services
There are many Asian dating sites that offer a free service for online singles Asian women date singles online is common these days because of this electronic world
Why Asian Women Are Popular to Western Men
The main reason that a Western man date or marry an Asian woman is the look Asian women have shiny black hair, slim figures, and attractive eyes to attract many men
Japanese Single Women and Japan Girls at Asian Dating Sites
I think that it is easier to find a date on line than all the other places The Japanese sites online of dating had thundered to connect all the Asian men and single women the ones with the others
New DVD Reveals How to Seduce the Asian Woman of Your Dreams
In the new DVD entitled 'How to Hook Up with Asian Girls', noted pick up artist for the ABCs of Attraction and motivational speaker Johnny Wolf helps men learn how to meet, attract, date and seduce Asian women.
Asian Women - How to Date & Marry an Asian Woman
Asian women are beautiful in their characteristics An Asian wife can cook daily meals while her husband sit on the couch watching football games